//
//  GoToWebView.m
//  EJLX
//
//  Created by adc on 15/11/9.
//  Copyright © 2015年 江苏一键联信息科技有限公司. All rights reserved.
//

#import "GoToWebView.h"
#import "NavAndTbbarView.h"
@interface GoToWebView ()

@end

@implementation GoToWebView

-(instancetype)initWithurl:(NSURL *)url title:(NSString *)titleName{
    if (self = [self init]) {
        _url = [self cleanURL:url];
        self.navigationController.navigationBarHidden = YES;
       // self.title = titleName;
        self.titleString = titleName;
    }
    return self;
}
-(NSURL *)cleanURL:(NSURL*)url{
    if (url.scheme.length == 0) {
        url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@",[url absoluteString]]];
    }
    return url;
}
- (void)viewDidLoad {
    [super viewDidLoad];
   // self.navigationController.navigationBarHidden = NO;
   // self.navigationController.navigationBarHidden = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatNav];
    self.web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 64, WIDE, HEIGHT-64)];
    self.web.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    self.web.backgroundColor = [UIColor clearColor];
    self.web.scalesPageToFit = YES;
    self.web.contentMode = UIViewContentModeRedraw;
    self.web.opaque = YES;
    [self.web loadRequest:[NSURLRequest requestWithURL:self.url]];
    
//    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回箭头"] style:UIBarButtonItemStyleDone  target:self action:@selector(backButtonTapped:)];
// 
//    self.navigationItem.leftBarButtonItem = backButton;
    [self.view addSubview:self.web];
 
}
-(void)creatNav{
    UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, WIDE, 44)];
    navView.backgroundColor = RGB_COLOR(0x00c49f);
    [self.view addSubview:navView];
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(10, 7, 30, 30);
    leftBtn.layer.cornerRadius = 20;
    [leftBtn setImage:[UIImage imageNamed:@"返回箭头"] forState:UIControlStateNormal] ;
    [leftBtn addTarget:self action:@selector(backBtn) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:leftBtn];
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(WIDE/2-60, 7, 120, 30  )];
    title.text = self.titleString;
    title.textAlignment = NSTextAlignmentCenter;
    title.textColor = [UIColor whiteColor];
    [navView addSubview:title];
    
}

-(void)backBtn{
    [self.web goBack];
    
    [self.navigationController popViewControllerAnimated:YES];
}
//-(void)backButtonTapped:(UIButton *)sender{
//    [self.web goBack];
//    
//    [self.navigationController popViewControllerAnimated:YES];
//    
//}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
